// 手机号
export const phone = (rule, value) => {
  let reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
  if (rule.required) {
    if (value === null || value === "" || value === undefined) {
      return Promise.reject("手机号不能为空！");
    } else if (!reg.test(value)) {
      return Promise.reject("请输入正确手机号");
    } else {
      return Promise.resolve();
    }
  }
};

// 邮箱
export const email = (rule, value) => {
  let reg = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+(\.com|.net)$/;
  if (rule.required) {
    if (value === null || value === "" || value === undefined) {
      return Promise.reject("邮箱不能为空！");
    } else if (!reg.test(value)) {
      return Promise.reject("请输入正确邮箱");
    } else {
      return Promise.resolve();
    }
  } else {
    if (!reg.test(value)) {
      return Promise.reject("请输入正确邮箱");
    } else {
      return Promise.resolve();
    }
  }
};

// 密码难度
export const password = (rule, value) => {
  let reg = /(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[\S])^[0-9A-Za-z\S]{8,}$/g;
  if (rule.required) {
    if (value === null || value === "" || value === undefined) {
      return Promise.reject("密码不能为空！");
    } else if (!reg.test(value)) {
      return Promise.reject("数字和大小写字母组合，至少8位");
    } else {
      return Promise.resolve();
    }
  }
};
